﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAC.sqlHelper;
using SAC.Elink;
using SAC.Helper;
using System.Collections;
using System.Data;
using SAC.Power;
using SAC.Plink;
using SAC.DB2;

namespace DAL
{
    public class DALData
    {
        int ret = 0;
        int tmpDay = 0;
        int count;
        double pVal = 0;
        string sql = "";
        string pName;
        string rlDBType = "";
        string rtDBType = "";
        string errMsg = "";
        string mTimeEnd = "";
        string jTimeEnd = "";
        string yTimeEnd = "";
        string mTimeBegin = "";
        string yTimeBegin = "";
        string jTimeBegin = "";

        string pGl1 = "WHSIS.U1APSH.U1A04013";
        string pGl2 = "WHSIS.U2APSH.U2A04013";

        DateTime tmpTime;
        DateTime mtEnd;  //月末
        DateTime jtEnd;  //季末
        DateTime ytEnd;  //年末
        DateTime mtBegin;
        DateTime jtBegin;
        DateTime ytBegin;

        Elink ek = new Elink();
        Plink pk = new Plink();
        StrHelper sh = new StrHelper();
        DALPubMehtod pm = new DALPubMehtod();

        /// <summary>
        /// 维护方法
        /// </summary>
        /// <param name="repName"></param>       
        /// <returns></returns>
        public ArrayList RetArrsByData(string repName)
        {
            string[] zb = null;
            string[] un = null;
            string[] lay = null;
            string[] ID1 = new string[500];
            string[] ID2 = new string[500];

            DataTable dt1 = null;
            DataTable dt2 = null;

            count = pm.GetCountData(repName);

            ArrayList list = new ArrayList();

            this.init();

            try
            {
                zb = new string[count + 1];
                un = new string[count + 1];
                lay = new string[count + 1];

                if (repName == "电能质量技术监督报表")
                    sql = "select * from T_Sheet_SheetPara where 报表名称='" + repName + "' and 机组=1  and (参数类型='其它') order by ID_KEY asc";
                else
                    sql = "select * from T_Sheet_SheetPara where 报表名称='" + repName + "' and 机组=1  and (参数类型='平均' or 参数类型='累计') order by ID_KEY asc";

                if (rlDBType == "SQL")
                    dt1 = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt1 = DBdb2.RunDataTable(sql, out errMsg);

                if (repName == "电能质量技术监督报表")
                    sql = "select * from T_Sheet_SheetPara where 报表名称='" + repName + "' and 机组=2  and (参数类型='其它') order by ID_KEY asc";
                else
                    sql = "select * from T_Sheet_SheetPara where 报表名称='" + repName + "' and 机组=2  and (参数类型='平均' or 参数类型='累计') order by ID_KEY asc";

                if (rlDBType == "SQL")
                    dt2 = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt2 = DBdb2.RunDataTable(sql, out errMsg);

                for (int i = 0; i < dt1.Rows.Count; i++)
                {
                    zb[i] = dt1.Rows[i]["参数名"].ToString();
                    un[i] = dt1.Rows[i]["单位"].ToString();
                    lay[i] = dt1.Rows[i]["设计值"].ToString();

                    if (dt1 != null && dt1.Rows.Count > 0)
                    {
                        if (dt1.Rows[i]["ID_KEY"] == null || dt1.Rows[i]["ID_KEY"].ToString() == "")
                            ID1[i] = "";
                        else
                            ID1[i] = dt1.Rows[i]["ID_KEY"].ToString();
                    }
                    else
                        ID1[i] = "";

                    if (dt2 != null && dt2.Rows.Count > 0)
                    {
                        if (dt2.Rows[i]["ID_KEY"] == null || dt2.Rows[i]["ID_KEY"].ToString() == "")
                            ID2[i] = "";
                        else
                            ID2[i] = dt2.Rows[i]["ID_KEY"].ToString();
                    }
                    else
                        ID2[i] = "";
                }
            }
            catch { }

            list.Add(zb);
            list.Add(un);
            list.Add(lay);
            list.Add(ID1);
            list.Add(ID2);

            return list;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataRow RetDataRowByID(string id)
        {
            this.init();

            string sql = "select * from T_sheet_sheetPara where ID_key =" + id;

            DataRow dr;
            if (rlDBType == "SQL")
                dr = DBsql.RunDataRow(sql, out errMsg);
            else
                dr = DBdb2.RunDataRow(sql, out errMsg);

            return dr;
        }

        //日数据读取
        public string RetValue(string hPoint, string unit, string type, string qsrq, string jsrq)
        {
            string bname;
            string sql;

            this.init();
            //取到小时点,进而获取数据表ID;
            DataRow drS;

            if (rlDBType == "SQL")
                drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + hPoint + "'", out errMsg);
            else
                drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + hPoint + "'", out errMsg);

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + hPoint + "'", out errMsg);
            }

            try
            {
                string pId = drS["统计ID"].ToString();

                if (unit == "1")
                    bname = "实时统计数据表1";
                else
                    bname = "实时统计数据表2";

                if (type == "平均")
                    sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pId + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "'";
                else
                    sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pId + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "'";

                object obj = null;

                if (rlDBType == "SQL")
                    obj = DBsql.RunSingle(sql, out errMsg);
                else
                    obj = DBdb2.RunSingle(sql, out errMsg);

                if (obj == null)//|| obj.ToString() == ""
                    return "0";
                else
                    return Double.Parse(obj.ToString()).ToString("f4");
            }
            catch (Exception ce)
            {
                return "没有记录";
            }
        }

        //班值数据读取
        public DataTable RetValueBz(string hPoint, string unit, string type, string qsrq, string jsrq)
        {
            string sql;
            DataTable dt = new DataTable();
            this.init();
            //取到小时点,进而获取数据表ID;
            DataRow drS;

            if (rlDBType == "SQL")
                drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + hPoint + "'", out errMsg);
            else
                drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + hPoint + "'", out errMsg);

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS != null)
            {
                string pId = drS["统计ID"].ToString();

                sql = "select * from 统计数据值日表 where 机组=" + unit + " and 统计ID ='" + pId + "' and 时间 between '" + qsrq + "' and '" + jsrq + "'";

                if (rlDBType == "SQL")
                    dt = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt = DBdb2.RunDataTable(sql, out errMsg);
            }
            return dt;
        }

        //小时数据读取
        public ArrayList RetValueArrs(string hPoint, string unit, string type, string qsrq, string jsrq)
        {
            ArrayList list = new ArrayList();

            string bname;
            string sql;

            string[] value = new string[24];
            string[] date = new string[24];
            string[] tj = new string[24];

            //取到小时点,进而获取数据表ID;
            this.init();

            DataRow drS = null;

            if (rlDBType == "SQL")
                drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + hPoint + "'", out errMsg);
            else
                drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + hPoint + "'", out errMsg);

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + hPoint + "'", out errMsg);
            }

            if (drS == null)
            {
                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + hPoint + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + hPoint + "'", out errMsg);
            }


            try
            {
                string pId = drS["统计ID"].ToString();

                if (unit == "1")
                    bname = "实时统计数据表1";
                else
                    bname = "实时统计数据表2";

                if (type == "平均")
                    sql = "select * from " + bname + " where (统计ID = '" + pId + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' order by 时间 asc";
                else
                    sql = "select * from " + bname + " where (统计ID = '" + pId + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' order by 时间 asc";

                DataTable dtHour = null;

                if (rlDBType == "SQL")
                    dtHour = DBsql.RunDataTable(sql, out errMsg);
                else
                    dtHour = DBdb2.RunDataTable(sql, out errMsg);

                if (dtHour.Rows.Count > 0)
                {
                    for (int i = 0; i < dtHour.Rows.Count; i++)
                    {
                        value[i] = double.Parse(dtHour.Rows[i]["统计值"].ToString()).ToString("f4");
                        date[i] = dtHour.Rows[i]["时间"].ToString();
                        tj[i] = dtHour.Rows[i]["标记"].ToString();
                    }
                }
                else
                {
                    for (int i = 0; i < 24; i++)
                    {
                        value[i] = "";
                        date[i] = DateTime.Parse(qsrq).ToString("yyyy-MM-dd '" + i + "':mm:ss");
                        tj[i] = "0";
                    }
                }

                list.Add(value);
                list.Add(date);
                list.Add(tj);
            }
            catch (Exception ex)
            {

            }

            return list;
        }

        //小时数据保存
        public bool RetIsTrueToSaveHours(string id, string jz, string time, string[] val, string[] bj)
        {
            string hPoint;
            string dPoint;
            string mPoint;
            string yPoint;
            string jPoint;
            string zbType;
            string bname;
            string pId;
            string iJidu = "";
            string nJidu = "";

            bool flag = false;

            if (jz == "1")
            {
                bname = "实时统计数据表1";
                pName = pGl1;
            }
            else
            {
                bname = "实时统计数据表2";
                pName = pGl2;
            }

            string sql = "select * from T_sheet_sheetPara where ID_key= " + id;

            DataRow drSheet = DBsql.RunDataRow(sql, out errMsg);

            if (drSheet != null)
            {
                hPoint = drSheet["小时点"].ToString();
                dPoint = drSheet["日点"].ToString(); ;
                mPoint = drSheet["月点"].ToString(); ;
                yPoint = drSheet["年点"].ToString(); ;
                jPoint = drSheet["季点"].ToString(); ;
                zbType = drSheet["参数类型"].ToString();

                DateTime input = DateTime.Parse(time);
                DateTime dtNow = DateTime.Now;

                iJidu = sh.GetJidu(input);
                nJidu = sh.GetJidu(dtNow);

                DataRow drS = null;

                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                try
                {
                    pId = drS["统计ID"].ToString();

                    ek.GetHisValueByTime(pName, input.ToString("yyyy-MM-dd 23:59:59"), ref ret, ref pVal);

                    if (pVal >= 200)
                    {
                        if (input.Year != dtNow.Year)
                        {
                            //非当年修改实时库和关系库

                            //修改小时数据
                            bool isH = this.SaveDataHour(hPoint, pId, jz, bname, zbType, val, bj, time);

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                                        if (isJ == true && valJidu == true)
                                        {
                                            bool isY = this.SaveDateYear(yPoint, pId, zbType, jz, bname, time);
                                            bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                                            if (isY == true && valYear == true)
                                                flag = true;
                                            else
                                                return false;
                                        }
                                        else
                                            return false;
                                    }
                                    else
                                        return false;
                                }
                                else
                                    return false;
                            }
                            else
                                return false;
                        }
                        else if (iJidu != nJidu)
                        {
                            bool isH = this.SaveDataHour(hPoint, pId, jz, bname, zbType, val, bj, time);

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                                        if (isJ == true && valJidu == true)
                                            flag = true;
                                    }
                                }
                            }
                        }
                        else if (input.Month != dtNow.Month)
                        {
                            bool isH = this.SaveDataHour(hPoint, pId, jz, bname, zbType, val, bj, time);

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    { flag = true; }
                                }
                            }
                        }
                        else if (input.Day != dtNow.Day)
                        {
                            bool isH = this.SaveDataHour(hPoint, pId, jz, bname, zbType, val, bj, time);

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                { flag = true; }
                            }
                        }
                        else
                        {
                            //当天
                            bool isH = this.SaveDataHourIS(hPoint, pId, jz, bname, zbType, val, bj, time);

                            if (isH == true)
                            {
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (valDay == true)
                                    flag = true;
                            }
                        }
                    }
                    else
                    {  //修改小时数据
                        bool isH = this.SaveDataHour(hPoint, pId, jz, bname, zbType, val, bj, time);

                        if (input.Day == dtNow.Day)
                        {
                            bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                            bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                        }
                        else
                        {
                            bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");
                            bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                        }

                        if (input.Month == dtNow.Month)
                        {
                            bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "0");
                            bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                        }
                        else
                        {
                            bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "1");
                            bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                        }

                        if (iJidu == nJidu)
                        {
                            bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "0");
                            bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                        }
                        else
                        {
                            bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "1");
                            bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                        }

                        if (dtNow.Year == input.Year)
                        {
                            bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "0");
                            bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");
                        }
                        else
                        {
                            bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "1");
                            bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                        }

                        flag = isH;
                    }

                }
                catch (Exception ex) { }
            }
            return flag;
        }

        //班值数据保存
        public bool RetIsTrueToSaveBz(string id, string jz, string time, string tjID, string[] val, string[] bz)
        {
            string hPoint;
            string dPoint;
            string mPoint;
            string yPoint;
            string jPoint;
            string zbType;
            string bname;
            string pId;
            string iJidu = "";
            string nJidu = "";

            bool Kt = false;
            bool flag = false;

            if (jz == "1")
            {
                bname = "实时统计数据表1";
                pName = pGl1;
            }
            else
            {
                bname = "实时统计数据表2";
                pName = pGl2;
            }

            pId = tjID;

            string sql = "select * from T_sheet_sheetPara where ID_key= " + id;

            DataRow drSheet = DBsql.RunDataRow(sql, out errMsg);

            if (drSheet != null)
            {
                hPoint = drSheet["小时点"].ToString();
                dPoint = drSheet["日点"].ToString(); ;
                mPoint = drSheet["月点"].ToString(); ;
                yPoint = drSheet["年点"].ToString(); ;
                jPoint = drSheet["季点"].ToString(); ;
                zbType = drSheet["参数类型"].ToString();

                DateTime input = DateTime.Parse(time);
                DateTime dtNow = DateTime.Now;

                iJidu = sh.GetJidu(input);
                nJidu = sh.GetJidu(dtNow);

                ek.GetHisValueByTime(pName, input.ToString("yyyy-MM-dd 23:59:59"), ref ret, ref pVal);

                if (pVal >= 200)
                {
                    bool isH = this.SaveDataHour(hPoint, bname, pId, time, zbType, jz, val, bz, out  Kt);

                    if (isH == true)
                    {
                        if (Kt == true)
                        {
                            string time1 = DateTime.Parse(time).AddDays(-1).ToString();

                            #region 班组跨天

                            if (input.Year != dtNow.Year)
                            {
                                //非当年修改实时库和关系库
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD1 = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time1);
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");

                                if (isD == true && valDay == true && isD1 == true && valDay1 == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                                    bool isM1 = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time1);
                                    bool valMon1 = this.SaveValue(pId, jz, zbType, bname, time1, "值月");

                                    if (isM1 == true && valMon1 == true && isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                                        bool isJ1 = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time1);
                                        bool valJidu1 = this.SaveValue(pId, jz, zbType, bname, time1, "值季");

                                        if (isJ == true && valJidu == true && isJ1 == true && valJidu1 == true)
                                        {
                                            bool isY = this.SaveDateYear(yPoint, pId, zbType, jz, bname, time);
                                            bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");
                                            bool isY1 = this.SaveDateYear(yPoint, pId, zbType, jz, bname, time1);
                                            bool valYear1 = this.SaveValue(pId, jz, zbType, bname, time1, "值年");

                                            if (isY == true && valYear == true && isY1 == true && valYear1 == true)
                                                flag = true;
                                            else
                                                return false;
                                        }
                                    }
                                }
                            }
                            else if (iJidu != nJidu)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD1 = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time1);
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");

                                if (isD == true && valDay == true && isD1 == true && valDay1 == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                                    bool isM1 = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time1);
                                    bool valMon1 = this.SaveValue(pId, jz, zbType, bname, time1, "值月");

                                    if (isM1 == true && valMon1 == true && isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                                        bool isJ1 = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time1);
                                        bool valJidu1 = this.SaveValue(pId, jz, zbType, bname, time1, "值季");

                                        if (isJ == true && valJidu == true && isJ1 == true && valJidu1 == true)
                                            flag = true;
                                    }
                                }
                            }
                            else if (input.Month != dtNow.Month)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD1 = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time1);
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");

                                if (isD == true && valDay == true && isD1 == true && valDay1 == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                                    bool isM1 = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time1);
                                    bool valMon1 = this.SaveValue(pId, jz, zbType, bname, time1, "值月");

                                    if (isM1 == true && valMon1 == true && isM == true && valMon == true)
                                    { flag = true; }
                                }
                            }
                            else if (input.Day != dtNow.Day)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD1 = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time1);
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");

                                if (isD == true && valDay == true && isD1 == true && valDay1 == true)
                                { flag = true; }
                            }
                            else
                            {
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");

                                if (valDay == true && valDay1 == true)
                                    flag = true;
                            }
                            #endregion
                        }
                        else
                        {
                            #region 班组不跨天
                            if (input.Year != dtNow.Year)
                            {
                                //非当年修改实时库和关系库
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                                        if (isJ == true && valJidu == true)
                                        {
                                            bool isY = this.SaveDateYear(yPoint, pId, zbType, jz, bname, time);
                                            bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                                            if (isY == true && valYear == true)
                                                flag = true;
                                            else
                                                return false;
                                        }
                                    }
                                }
                            }
                            else if (iJidu != nJidu)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                                        if (isJ == true && valJidu == true)
                                            flag = true;
                                    }
                                }
                            }
                            else if (input.Month != dtNow.Month)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    { flag = true; }
                                }
                            }
                            else if (input.Day != dtNow.Day)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                { flag = true; }
                            }
                            else
                            {
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (valDay == true)
                                    flag = true;
                            }
                            #endregion
                        }
                    }
                }
                else
                {
                    bool isH = false;

                    isH = this.SaveDataHour(hPoint, bname, pId, time, zbType, jz, val, bz, out  Kt);

                    if (isH == true)
                    {
                        if (Kt == true)
                        {
                            string time1 = DateTime.Parse(time).AddDays(-1).ToString();

                            #region 班组跨天
                            if (input.Day == dtNow.Day)
                            {
                                bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD1 = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time1, "0");
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");
                            }
                            else
                            {
                                bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD1 = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time1, "1");
                                bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");
                            }

                            if (input.Month == dtNow.Month)
                            {
                                bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "0");
                                bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                                bool isM1 = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time1, "0");
                                bool valMon1 = this.SaveValue(pId, jz, zbType, bname, time1, "值月");
                            }
                            else
                            {
                                bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "1");
                                bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                                bool isM1 = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time1, "1");
                                bool valMon1 = this.SaveValue(pId, jz, zbType, bname, time1, "值月");
                            }

                            if (iJidu == nJidu)
                            {
                                bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "0");
                                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                                bool isJ1 = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time1, "0");
                                bool valJidu1 = this.SaveValue(pId, jz, zbType, bname, time1, "值季");
                            }
                            else
                            {
                                bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "1");
                                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                                bool isJ1 = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time1, "1");
                                bool valJidu1 = this.SaveValue(pId, jz, zbType, bname, time1, "值季");
                            }

                            if (dtNow.Year == input.Year)
                            {
                                bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "0");
                                bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");
                                bool isY1 = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time1, "0");
                                bool valYear1 = this.SaveValue(pId, jz, zbType, bname, time1, "值年");
                            }
                            else
                            {
                                bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "1");
                                bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");
                                bool isY1 = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time1, "1");
                                bool valYear1 = this.SaveValue(pId, jz, zbType, bname, time1, "值年");
                            }

                            flag = isH;
                            #endregion
                        }
                        else
                        {
                            #region 班组不夸天
                            if (input.Day == dtNow.Day)
                            {
                                bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                            }
                            else
                            {
                                bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                            }

                            if (input.Month == dtNow.Month)
                            {
                                bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "0");
                                bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                            }
                            else
                            {
                                bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "1");
                                bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                            }

                            if (iJidu == nJidu)
                            {
                                bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "0");
                                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                            }
                            else
                            {
                                bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "1");
                                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                            }

                            if (dtNow.Year == input.Year)
                            {
                                bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "0");
                                bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");
                            }
                            else
                            {
                                bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "1");
                                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                            }

                            flag = isH;

                            #endregion
                        }
                    }
                }
            }

            return flag;
        }

        //日数据保存
        public bool RetIsTrueToSaveDay(string id, string jz, string time, string zbType, string value)
        {
            string hPoint;
            string dPoint;
            string mPoint;
            string yPoint;
            string jPoint;
            string bname;
            string pId;
            string iJidu = "";
            string nJidu = "";

            bool flag = false;

            if (jz == "1")
            {
                bname = "实时统计数据表1";
                pName = pGl1;
            }
            else
            {
                bname = "实时统计数据表2";
                pName = pGl2;
            }

            string sql = "select * from T_sheet_sheetPara where ID_key= " + id;

            DataRow drSheet = DBsql.RunDataRow(sql, out errMsg);

            if (drSheet != null)
            {
                hPoint = drSheet["小时点"].ToString();
                dPoint = drSheet["日点"].ToString(); ;
                mPoint = drSheet["月点"].ToString(); ;
                yPoint = drSheet["年点"].ToString(); ;
                jPoint = drSheet["季点"].ToString(); ;

                DateTime input = DateTime.Parse(time);
                DateTime dtNow = DateTime.Now;

                iJidu = sh.GetJidu(input);
                nJidu = sh.GetJidu(dtNow);

                DataRow drS = null;

                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                try
                {
                    pId = drS["统计ID"].ToString();

                    ek.GetHisValueByTime(pName, input.ToString("yyyy-MM-dd 23:59:59"), ref ret, ref pVal);

                    if (pVal >= 200)
                    {
                        if (input.Year != dtNow.Year)
                        {
                            //非当年修改实时库和关系库

                            //修改小时数据
                            bool isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "0");

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                                        if (isJ == true && valJidu == true)
                                        {
                                            bool isY = this.SaveDateYear(yPoint, pId, zbType, jz, bname, time);
                                            bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                                            if (isY == true && valYear == true)
                                                flag = true;
                                            else
                                                return false;
                                        }
                                        else
                                            return false;
                                    }
                                    else
                                        return false;
                                }
                                else
                                    return false;
                            }
                            else
                                return false;
                        }
                        else if (iJidu != nJidu)
                        {
                            bool isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "0");

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    {
                                        bool isJ = this.SaveDateJidu(jPoint, pId, zbType, jz, bname, time);
                                        bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                                        if (isJ == true && valJidu == true)
                                            flag = true;
                                    }
                                }
                            }
                        }
                        else if (input.Month != dtNow.Month)
                        {
                            bool isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "0");

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                {
                                    bool isM = this.SaveDateMonth(mPoint, pId, zbType, jz, bname, time);
                                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                                    if (isM == true && valMon == true)
                                    { flag = true; }
                                }
                            }
                        }
                        else if (input.Day != dtNow.Day)
                        {
                            bool isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "0");

                            if (isH == true)
                            {
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                                if (isD == true && valDay == true)
                                { flag = true; }
                            }
                        }
                        else
                        {
                            //当天
                            bool isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "1");

                            if (isH == true)
                            {
                                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                                bool isD = this.SaveDateDay(dPoint, pId, zbType, jz, bname, time);
                                if (valDay == true)
                                    flag = true;
                            }
                        }
                    }
                    else
                    {   //修改小时数据
                        bool isH = false;

                        if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                            isH = this.SavaDataHourByFH(hPoint, bname, pId, time, zbType, jz, value, "1");
                        else
                            isH = this.SavaDataHourByFH(hPoint, bname, pId, time, zbType, jz, value, "0");

                        if (input.Day == dtNow.Day)
                        {
                            bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                            bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                        }
                        else
                        {
                            bool isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");
                            bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                        }

                        if (input.Month == dtNow.Month)
                        {
                            bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "0");
                            bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                        }
                        else
                        {
                            bool isM = this.SaveDateMonthByFH(mPoint, pId, zbType, jz, bname, time, "1");
                            bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                        }

                        if (iJidu == nJidu)
                        {
                            bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "0");
                            bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                        }
                        else
                        {
                            bool isJ = this.SaveDateJiduByFH(jPoint, pId, zbType, jz, bname, time, "1");
                            bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                        }

                        if (dtNow.Year == input.Year)
                        {
                            bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "0");
                            bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");
                        }
                        else
                        {
                            bool isY = this.SaveDateYearByFH(yPoint, pId, zbType, jz, bname, time, "1");
                            bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                        }

                        flag = isH;
                    }
                }
                catch (Exception ex) { }
            }

            return flag;
        }

        //修改小时值[班值数据]
        private bool SaveDataHour(string hPoint, string bname, string pId, string time, string zbType, string jz, string[] val, string[] bz, out bool Kt)
        {
            object value;
            string qsrq;
            string jsrq;
            string qsrqPB = "";
            string jsrqPB = "";

            int k = -1;
            bool flag = false;

            DataRow drPB;
            DataRow drPB1;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            Kt = false;

            this.init();

            for (int i = 0; i < val.Length; i++)
            {
                if (val[i].ToString() != "")
                {
                    sql = "select * from 排班表 where 班组编号='" + bz[i] + "' and 起始时间 between '" + qsrq + "' and '" + jsrq + "'";

                    if (rlDBType == "SQL")
                        drPB = DBsql.RunDataRow(sql, out errMsg);
                    else
                        drPB = DBdb2.RunDataRow(sql, out errMsg);

                    if (drPB == null)
                    {
                        //跨天
                        //SQL
                        //sql = "select * from 排班表 where 班组编号=" + bz[i] + " and 起始时间 between '" + DateTime.Parse(qsrq).AddDays(-1).ToString() + "' and '" + DateTime.Parse(jsrq).AddDays(-1).ToString() + "'";
                        //DB2
                        sql = "select * from 排班表 where 班组编号='" + bz[i] + "' and 起始时间 between '" + qsrq + "' and '" + jsrq + "'";

                        if (rlDBType == "SQL")
                            drPB1 = DBsql.RunDataRow(sql, out errMsg);
                        else
                            drPB1 = DBdb2.RunDataRow(sql, out errMsg);

                        if (drPB1 != null)
                        {
                            Kt = true;

                            qsrqPB = drPB1["起始时间"].ToString();
                            jsrqPB = drPB1["结束时间"].ToString();
                        }
                    }
                    else
                    {
                        qsrqPB = drPB["起始时间"].ToString();
                        jsrqPB = drPB["结束时间"].ToString();
                    }

                    string[] date = sh.DateDiffHours(DateTime.Parse(jsrqPB), DateTime.Parse(qsrqPB));

                    sql = "delete from " + bname + " where 统计ID ='" + pId + "' and 时间 between '" + qsrqPB + "' and '" + jsrqPB + "' ";

                    bool isDel;

                    if (rlDBType == "SQL")
                        isDel = DBsql.RunNonQuery(sql, out errMsg);
                    else
                        isDel = DBdb2.RunNonQuery(sql, out errMsg);

                    if (isDel != true)
                        return false;
                    else
                    {
                        for (int j = 0; j < date.Length; j++)
                        {
                            if (val[i] != "")
                            {
                                if (zbType == "平均")
                                    value = double.Parse(val[i]);
                                else
                                    value = double.Parse(val[i]) / date.Length;
                            }
                            else
                                value = "0";
                            //SQL
                            //sql = "insert into " + bname + " (时间,统计值,统计ID,机组,标记) values ('" + date[j] + "','" + value.ToString() + "','" + pId + "','" + jz + "','1')";
                            //DB2
                            sql = "insert into " + bname + " (时间,统计值,统计ID,机组,标记) values ('" + date[j] + "'," + value.ToString() + ",'" + pId + "'," + jz + ",1)";
                            bool isNon;

                            if (rlDBType == "SQL")
                                isNon = DBsql.RunNonQuery(sql, out errMsg);
                            else
                                isNon = DBdb2.RunNonQuery(sql, out errMsg);

                            if (isNon == false)
                                return false;
                            else
                                flag = true;

                            string sDate = DateTime.Parse(date[j]).ToString("yyyy-MM-dd H:59:59");

                            if (hPoint != "")
                            {
                                if (rtDBType == "EDNA")
                                    k = ek.SetHisValue(ref hPoint, ref sDate, ref value);
                                else
                                    k = pk.SetHisValue(hPoint, sDate, ref value);
                            }
                        }
                    }
                }
            }
            return flag;
        }

        //修改小时值[日数据]
        private bool SavaDataHour(string hPoint, string bname, string pid, string time, string zbType, string jz, string val, string isDay)
        {
            string sql;
            string qsrq;
            string jsrq;
            object value;

            int k = -1;
            int j = 0;
            bool flag = false;

            DateTime dtNow = DateTime.Now;

            if (isDay == "0")
                j = 24;
            else
                j = dtNow.Hour;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            this.init();

            sql = "delete from " + bname + " where 统计ID ='" + pid + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' ";

            bool isDel;

            if (rlDBType == "SQL")
                isDel = DBsql.RunNonQuery(sql, out errMsg);
            else
                isDel = DBdb2.RunNonQuery(sql, out errMsg);

            if (isDel == true)
            {
                if (val != "")
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (zbType == "平均")
                            value = val;
                        else
                            value = double.Parse(val) / j;//
                        //SQL
                        //sql = "insert into " + bname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "','" + value + "','" + pid + "','" + jz + "','1')";
                        //DB2
                        sql = "insert into " + bname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "'," + value + ",'" + pid + "'," + jz + ",1)";

                        bool isNon;

                        if (rlDBType == "SQL")
                            isNon = DBsql.RunNonQuery(sql, out errMsg);
                        else
                            isNon = DBdb2.RunNonQuery(sql, out errMsg);

                        if (isNon == false)
                            return false;
                        else
                            flag = true;

                        string sDate = DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":59:59";

                        if (hPoint != "")
                        {
                            if (rtDBType == "EDNA")
                                k = ek.SetHisValue(ref hPoint, ref sDate, ref value);
                            else
                                k = pk.SetHisValue(hPoint, sDate, ref value);
                        }
                    }
                }
            }
            return flag;
        }

        //值日
        private bool SaveValueDay(string pid, string jz, string zbType, string bname, DataTable dt)
        {
            bool flag = false;
            object obj;
            string value;
            string qsrqH;
            string jsrqH;

            this.init();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                qsrqH = dt.Rows[i]["起始时间"].ToString();
                jsrqH = dt.Rows[i]["结束时间"].ToString();

                if (zbType == "平均")
                {
                    //SQL
                    //sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrqH + "' and  '" + jsrqH + "' and 标记=1 and 机组='" + jz + "'";
                    //DB2
                    sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrqH + "' and  '" + jsrqH + "' and 标记=1 and 机组=" + jz;
                }
                else
                {
                    //SQL
                    //sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrqH + "' and  '" + jsrqH + "' and 标记=1 and 机组=" + jz + "'";
                    //DB2
                    sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrqH + "' and  '" + jsrqH + "' and 标记=1 and 机组=" + jz;
                }
                try
                {
                    if (rlDBType == "SQL")
                        obj = DBsql.RunSingle(sql, out errMsg);
                    else
                        obj = DBdb2.RunSingle(sql, out errMsg);

                    if (obj.ToString() == "")
                        value = "0";
                    else
                        value = obj.ToString();
                }
                catch (Exception ce)
                { value = "0"; }

                //sql = "delete from 统计数据值日表 where 统计ID='" + pid + "' and 时间='" + DateTime.Parse(qsrqH).ToString("yyyy-MM-dd") + "' and 机组=" + jz + " and 班组=" + dt.Rows[i]["班组编号"].ToString();
                sql = "delete from 统计数据值日表 where 统计ID='" + pid + "' and 时间='" + DateTime.Parse(qsrqH).ToString("yyyy-MM-dd HH:mm:ss") + "' and 机组=" + jz + " and 班组=" + dt.Rows[i]["班组编号"].ToString();

                bool isDel;

                if (rlDBType == "SQL")
                    isDel = DBsql.RunNonQuery(sql, out errMsg);
                else
                    isDel = DBdb2.RunNonQuery(sql, out errMsg);

                if (isDel == true)
                {
                    //DB2
                    sql = "insert into 统计数据值日表 (统计ID,统计值,时间,机组,班组) values ('" + pid + "'," + value + ",'" + DateTime.Parse(qsrqH).ToString("yyyy-MM-dd HH:mm:ss") + "'," + jz + "," + dt.Rows[i]["班组编号"].ToString() + ")";
                    //SQL
                    //sql = "insert into 统计数据值日表 (统计ID,统计值,时间,机组,班组) values ('" + pid + "','" + value + "','" + DateTime.Parse(qsrqH).ToString("yyyy-MM-dd") + "'," + jz + "," + dt.Rows[i]["班组编号"].ToString() + ")";

                    bool isNon;

                    if (rlDBType == "SQL")
                        isNon = DBsql.RunNonQuery(sql, out errMsg);
                    else
                        isNon = DBdb2.RunNonQuery(sql, out errMsg);

                    if (isNon == false)
                        return false;
                    else
                        flag = true;
                }
            }

            return flag;
        }

        //值月、季、年
        private bool SaveValueMonOrJiOrYear(string pid, string jz, string zbType, string bname, DataTable dt, string qsrq, string jsrq)
        {
            bool flag = false;
            object obj;
            string value;

            this.init();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (zbType == "平均")
                    sql = "select avg(统计值) from 统计数据值日表 where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 机组=" + jz + " and 班组=" + dt.Rows[i]["班组编号"].ToString();
                else
                    sql = "select sum(统计值) from 统计数据值日表 where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 机组=" + jz + " and 班组=" + dt.Rows[i]["班组编号"].ToString();
                //if (zbType == "平均")
                //    sql = "select avg(统计值) from 统计数据值日表 where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 机组='" + jz + "' and 班组=" + dt.Rows[i]["班组编号"].ToString();
                //else
                //    sql = "select sum(统计值) from 统计数据值日表 where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 机组='" + jz + "' and 班组=" + dt.Rows[i]["班组编号"].ToString();

                try
                {
                    if (rlDBType == "SQL")
                        obj = DBsql.RunSingle(sql, out errMsg);
                    else
                        obj = DBdb2.RunSingle(sql, out errMsg);

                    if (obj.ToString() == "")
                        value = "0";
                    else
                        value = obj.ToString();
                }
                catch (Exception ce)
                { value = "0"; }

                //sql = "delete from " + bname + " where 统计ID='" + pid + "' and 时间='" + DateTime.Parse(qsrq).ToString("yyyy-MM-dd") + "' and 机组=" + jz + " and 班组=" + dt.Rows[i]["班组编号"].ToString();
                sql = "delete from " + bname + " where 统计ID='" + pid + "' and 时间='" + DateTime.Parse(qsrq).ToString("yyyy-MM-dd HH:mm:ss") + "' and 机组=" + jz + " and 班组=" + dt.Rows[i]["班组编号"].ToString();

                bool isDel;

                if (rlDBType == "SQL")
                    isDel = DBsql.RunNonQuery(sql, out errMsg);
                else
                    isDel = DBdb2.RunNonQuery(sql, out errMsg);

                if (isDel == true)
                {
                    //sql = "insert into " + bname + " (统计ID,统计值,时间,机组,班组) values ('" + pid + "','" + value + "','" + DateTime.Parse(qsrq).ToString("yyyy-MM-dd") + "'," + jz + "," + dt.Rows[i]["班组编号"].ToString() + ")";
                    sql = "insert into " + bname + " (统计ID,统计值,时间,机组,班组) values ('" + pid + "'," + value + ",'" + DateTime.Parse(qsrq).ToString("yyyy-MM-dd HH:mm:ss") + "'," + jz + "," + dt.Rows[i]["班组编号"].ToString() + ")";

                    bool isNon;

                    if (rlDBType == "SQL")
                        isNon = DBsql.RunNonQuery(sql, out errMsg);
                    else
                        isNon = DBdb2.RunNonQuery(sql, out errMsg);

                    if (isNon == false)
                        return false;
                    else
                        flag = true;
                }
            }
            return flag;
        }

        //值日数据修改[值数据修改]
        private bool SaveValue(string pid, string jz, string zbType, string bname, string btime, string repName)
        {
            bool flag = false;
            string sql;
            string qsrq;
            string jsrq;

            qsrq = DateTime.Parse(btime).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(btime).ToString("yyyy-MM-dd 23:59:59");

            this.init();

            DataTable dtPJ = new DataTable();

            dtPJ.Columns.Add("ID_KEY", typeof(string));
            dtPJ.Columns.Add("起始时间", typeof(string));
            dtPJ.Columns.Add("结束时间", typeof(string));
            dtPJ.Columns.Add("班组编号", typeof(string));

            sql = "select * from " + bname + " where 统计ID='" + pid + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' and 标记=1 order by 时间 asc";

            DataTable dtH;

            if (rlDBType == "SQL")
                dtH = DBsql.RunDataTable(sql, out errMsg);
            else
                dtH = DBdb2.RunDataTable(sql, out errMsg);

            if (dtH != null && dtH.Rows.Count > 0)
            {
                string dtTime;

                for (int i = 0; i < dtH.Rows.Count; i++)
                {
                    DataRow dw = dtPJ.NewRow();

                    dtTime = dtH.Rows[i]["时间"].ToString();

                    sql = "select * from 排班表 where '" + dtTime + "' BETWEEN 起始时间 AND 结束时间";

                    DataRow drPB;

                    if (rlDBType == "SQL")
                        drPB = DBsql.RunDataRow(sql, out errMsg);
                    else
                        drPB = DBdb2.RunDataRow(sql, out errMsg);

                    if (drPB != null)
                    {
                        dw[0] = drPB["ID_KEY"].ToString();
                        dw[1] = drPB["起始时间"].ToString();
                        dw[2] = drPB["结束时间"].ToString();
                        dw[3] = drPB["班组编号"].ToString();
                    }

                    dtPJ.Rows.Add(dw);
                }

                DataView two = new DataView(dtPJ);
                two.Sort = "ID_KEY";
                DataTable newTable = two.ToTable(true, "ID_KEY", "起始时间", "结束时间", "班组编号");

                if (repName == "值日")
                {
                    flag = this.SaveValueDay(pid, jz, zbType, bname, newTable);
                }
                else if (repName == "值月")
                {
                    bname = "统计数据值月表";

                    qsrq = sh.FirstDayOfMonth(DateTime.Parse(btime)).ToString("yyyy-MM-dd 0:00:00");
                    jsrq = sh.LastDayOfMonth(DateTime.Parse(btime)).ToString("yyyy-MM-dd 23:59:59");

                    flag = this.SaveValueMonOrJiOrYear(pid, jz, zbType, bname, newTable, qsrq, jsrq);
                }
                else if (repName == "值季")
                {
                    bname = "统计数据值季表";

                    qsrq = DateTime.Parse(sh.GetInceDay(DateTime.Parse(btime))).ToString("yyyy-MM-dd 0:00:00");
                    jsrq = DateTime.Parse(sh.GetEndDay(DateTime.Parse(btime))).ToString("yyyy-MM-dd 23:59:59");

                    flag = this.SaveValueMonOrJiOrYear(pid, jz, zbType, bname, newTable, qsrq, jsrq);
                }
                else if (repName == "值年")
                {
                    bname = "统计数据值年表";

                    qsrq = DateTime.Parse(btime).ToString("yyyy-01-01 0:00:00");
                    jsrq = DateTime.Parse(btime).ToString("yyyy-12-31 23:59:59");

                    flag = this.SaveValueMonOrJiOrYear(pid, jz, zbType, bname, newTable, qsrq, jsrq);
                }
            }
            return flag;
        }

        //修改小时值[小时修改]
        public bool SaveDataHour(string point, string pid, string jz, string Tname, string zbType, string[] val, string[] bj, string time)
        {
            string sql;
            string qsrq;
            string jsrq;
            object value;

            int k = -1;
            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            sql = "delete from " + Tname + " where 统计ID ='" + pid + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' ";

            this.init();

            bool isDel = false;

            if (rlDBType == "SQL")
                isDel = DBsql.RunNonQuery(sql, out errMsg);
            else
                isDel = DBdb2.RunNonQuery(sql, out errMsg);

            if (isDel == true)
            {
                if (zbType == "平均" || zbType == "累计")
                {
                    if (val != null && val.Length > 0)
                    {
                        //修改小时数据
                        for (int i = 0; i < 24; i++)
                        {
                            if (val[i] != null && val[i] != "")
                            {
                                value = val[i].ToString();
                                //SQL
                                //sql = "insert into " + Tname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "','" + value + "','" + pid + "','" + jz + "','" + bj[i] + "')";
                                //DB2
                                sql = "insert into " + Tname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "'," + value + ",'" + pid + "'," + jz + "," + bj[i] + ")";

                                bool isNon = false;

                                if (rlDBType == "SQL")
                                    isNon = DBsql.RunNonQuery(sql, out errMsg);
                                else
                                    isNon = DBdb2.RunNonQuery(sql, out errMsg);

                                if (isNon == false)
                                    return false;
                                else
                                    flag = true;

                                string sDate = DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":59:59";

                                if (point != "")
                                {
                                    if (rtDBType == "EDNA")
                                        k = ek.SetHisValue(ref point, ref sDate, ref value);
                                    else
                                        k = pk.SetHisValue(pName, sDate, ref value);
                                }
                            }
                        }
                    }
                }
            }
            return flag;
        }

        //修改小时值[小时修改:当日]
        public bool SaveDataHourIS(string point, string pid, string jz, string Tname, string zbType, string[] val, string[] bj, string time)
        {
            string sql;
            string qsrq;
            string jsrq;
            object value;

            int k = -1;
            bool flag = false;

            DateTime dt = DateTime.Now;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            this.init();

            sql = "delete from " + Tname + " where 统计ID ='" + pid + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' ";

            bool isDel = false;

            if (rlDBType == "SQL")
                isDel = DBsql.RunNonQuery(sql, out errMsg);
            else
                isDel = DBdb2.RunNonQuery(sql, out errMsg);

            if (isDel == true)
            {
                if (zbType == "平均" || zbType == "累计")
                {
                    if (val != null && val.Length > 0)
                    {
                        //修改小时数据
                        for (int i = 0; i < dt.Hour; i++)
                        {
                            if (val[i] != null && val[i] != "")
                            {
                                value = val[i].ToString();
                                //SQL
                                //sql = "insert into " + Tname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "','" + value + "','" + pid + "','" + jz + "','" + bj[i] + "')";
                                //DB2
                                sql = "insert into " + Tname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "'," + value + ",'" + pid + "'," + jz + "," + bj[i] + ")";

                                bool isNon = false;

                                if (rlDBType == "SQL")
                                    isNon = DBsql.RunNonQuery(sql, out errMsg);
                                else
                                    isNon = DBdb2.RunNonQuery(sql, out errMsg);

                                if (isNon == false)
                                    return false;
                                else
                                    flag = true;

                                string sDate = DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":59:59";

                                if (point != "")
                                {
                                    if (rtDBType == "EDNA")
                                        k = ek.SetHisValue(ref point, ref sDate, ref value);
                                    else
                                        k = pk.SetHisValue(point, time, ref value);
                                }
                            }
                        }
                    }
                }
            }
            return flag;
        }

        //修改日值[小时修改]
        public bool SaveDateDay(string point, string pid, string zbType, string jz, string bname, string time)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            sDate = jsrq;

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value != "")
            {
                k = ek.SetHisValue(ref point, ref sDate, ref value);
                //ek.s
                if (k == 0)
                    flag = true;

            }
            return flag;
        }

        //修改小时值[日数据-负荷小于200]
        private bool SavaDataHourByFH(string hPoint, string bname, string pid, string time, string zbType, string jz, string val, string isDay)
        {
            string sql;
            string qsrq;
            string jsrq;
            object value;

            int k = -1;
            int j = 0;
            bool flag = false;

            DateTime dtNow = DateTime.Now;

            if (isDay == "0")
                j = 24;
            else
                j = dtNow.Hour;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            sql = "delete from " + bname + " where 统计ID ='" + pid + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' ";

            bool isDel = DBsql.RunNonQuery(sql, out errMsg);

            if (isDel == true)
            {
                if (val != "")
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (zbType == "平均")
                            value = val;
                        else
                            value = double.Parse(val) / j;//
                        //SQL
                        //sql = "insert into " + bname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "','" + value + "','" + pid + "','" + jz + "','1')";
                        //DB2
                        sql = "insert into " + bname + " (时间,统计值,统计ID,机组,标记) values ('" + DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":00:00" + "'," + value + ",'" + pid + "'," + jz + ",1)";

                        bool isNon = DBsql.RunNonQuery(sql, out errMsg);

                        if (isNon == false)
                            return false;
                        else
                            flag = true;

                        string sDate = DateTime.Parse(qsrq).ToShortDateString() + " " + i + ":59:59";

                        if (hPoint != "")
                            k = ek.SetHisValue(ref hPoint, ref sDate, ref value);
                    }
                }
            }
            return flag;
        }

        //修改日值[小时修改--负荷小于200]
        public bool SaveDateDayByFH(string point, string pid, string zbType, string jz, string bname, string time, string isDay)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            sDate = jsrq;

            this.init();

            if (zbType == "平均")
            {
                //SQL
                //sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
                //DB2
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组=" + jz + "";
            }
            else
            {
                //SQL
                //sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
                //DB2
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组=" + jz + "";
            }
            try
            {
                if (rlDBType == "SQL")
                    obj = DBsql.RunSingle(sql, out errMsg);
                else
                    obj = DBdb2.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value != "")
            {
                if (isDay == "1")
                {
                    if (rtDBType == "EDNA")
                        k = ek.SetHisValue(ref point, ref sDate, ref value);
                    else
                        k = pk.SetHisValue(point, sDate, ref value);
                }
                else
                {
                    sDate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd H:59:59");

                    if (rtDBType == "EDNA")
                        k = ek.SetHisValue(ref point, ref sDate, ref value);
                    else
                        k = ek.SetCurValue(ref point, ref value);
                }

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        //修改月值[小时修改-负荷小于200]
        public bool SaveDateMonthByFH(string point, string pid, string zbType, string jz, string bname, string time, string isDay)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-01 0:00:00");
            jsrq = sh.LastDayOfMonth(DateTime.Parse(time)).ToString("yyyy-MM-dd 23:59:59");

            sDate = jsrq;// DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value.ToString() != "")
            {
                if (isDay == "1")
                    k = ek.SetHisValue(ref point, ref sDate, ref value);
                else
                {
                    sDate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd H:59:59");
                    k = ek.SetHisValue(ref point, ref sDate, ref value);
                }
                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        //修改季值[小时修改-负荷小于200]
        public bool SaveDateJiduByFH(string point, string pid, string zbType, string jz, string bname, string time, string isDay)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(sh.GetInceDay(DateTime.Parse(time)).ToString()).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(sh.GetEndDay(DateTime.Parse(time)).ToString()).ToString("yyyy-MM-dd 23:59:59");

            sDate = jsrq;

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";

            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value != "")
            {
                if (isDay == "1")
                    k = ek.SetHisValue(ref point, ref sDate, ref value);
                else
                {
                    sDate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd H:59:59");
                    k = ek.SetHisValue(ref point, ref sDate, ref value);
                }

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        //修改年值[小时修改-负荷小于200]
        public bool SaveDateYearByFH(string point, string pid, string zbType, string jz, string bname, string time, string isDay)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-01-01 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-12-31 23:59:59");

            sDate = jsrq;

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";

            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value != "")
            {
                if (isDay == "1")
                    k = ek.SetHisValue(ref point, ref sDate, ref value);
                else
                {
                    sDate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd H:59:59");
                    k = ek.SetHisValue(ref point, ref sDate, ref value);
                }

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        //修改月值[小时修改]
        public bool SaveDateMonth(string point, string pid, string zbType, string jz, string bname, string time)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-01 0:00:00");
            jsrq = sh.LastDayOfMonth(DateTime.Parse(time)).ToString("yyyy-MM-dd 23:59:59");

            sDate = jsrq;// DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value.ToString() != "")
            {
                k = ek.SetHisValue(ref point, ref sDate, ref value);

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        // 修改季值[小时修改]
        public bool SaveDateJidu(string point, string pid, string zbType, string jz, string bname, string time)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(sh.GetInceDay(DateTime.Parse(time)).ToString()).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(sh.GetEndDay(DateTime.Parse(time)).ToString()).ToString("yyyy-MM-dd 23:59:59");

            sDate = jsrq;

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";

            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value != "")
            {
                k = ek.SetHisValue(ref point, ref sDate, ref value);

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        // 修改年值[小时修改]
        public bool SaveDateYear(string point, string pid, string zbType, string jz, string bname, string time)
        {
            int k = -1;

            string sql;
            string qsrq;
            string jsrq;
            string sDate;
            object obj;
            object value;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-01-01 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-12-31 23:59:59");

            sDate = jsrq;

            if (zbType == "平均")
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
            else
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";

            try
            {
                obj = DBsql.RunSingle(sql, out errMsg);

                if (obj.ToString() == "")
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value != "")
            {
                k = ek.SetHisValue(ref point, ref sDate, ref value);

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        #region 指标数据保存

        //日数据保存
        public bool RetIsTrueToSaveDayNew(string id, string jz, string time, string zbType, string value)
        {
            bool isD = false;
            bool isM = false;
            bool isJ = false;
            bool isY = false;

            string hPoint;
            string dPoint;
            string mPoint;
            string yPoint;
            string jPoint;
            string bname;
            string pId;
            string iJidu = "";
            string nJidu = "";

            bool flag = false;

            this.init();

            if (jz == "1")
            {
                bname = "实时统计数据表1";
                pName = pGl1;
            }
            else
            {
                bname = "实时统计数据表2";
                pName = pGl2;
            }

            string sql = "select * from T_sheet_sheetPara where ID_key= " + id;

            DataRow drSheet;

            if (rlDBType == "SQL")
                drSheet = DBsql.RunDataRow(sql, out errMsg);
            else
                drSheet = DBdb2.RunDataRow(sql, out errMsg);

            if (drSheet != null)
            {
                hPoint = drSheet["小时点"].ToString();
                dPoint = drSheet["日点"].ToString(); ;
                mPoint = drSheet["月点"].ToString(); ;
                yPoint = drSheet["年点"].ToString(); ;
                jPoint = drSheet["季点"].ToString(); ;

                DateTime input = DateTime.Parse(time);
                DateTime dtNow = DateTime.Now;

                iJidu = sh.GetJidu(input);
                nJidu = sh.GetJidu(dtNow);

                DataRow drS;

                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }
                pId = drS["统计ID"].ToString();

                bool isH = false;

                //修改小时数据
                if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                    isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "1");
                else
                    isH = this.SavaDataHour(hPoint, bname, pId, time, zbType, jz, value, "0");

                //修改日数据
                if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                    isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                else
                    isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");

                //修改值数据
                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                //月末
                if (sh.DateDiffDays(dtNow, input) > dtNow.Day)
                    mTimeEnd = sh.LastDayOfMonth(input).ToString();
                else
                    mTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                //季末
                if (iJidu == nJidu && input.Year == dtNow.Year)
                    jTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");
                else
                    jTimeEnd = sh.GetEndDay(input);

                //年末
                if (input.Year != dtNow.Year)
                    yTimeEnd = input.ToString("yyyy-12-31");
                else
                    yTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                mtBegin = sh.FirstDayOfMonth(input);
                jtBegin = DateTime.Parse(sh.GetInceDay(input));
                ytBegin = DateTime.Parse(input.ToString("yyyy-01-01"));

                for (int i = 0; i <= sh.DateDiffDays(DateTime.Parse(yTimeEnd), input); i++)
                {
                    tmpTime = DateTime.Parse(input.AddDays(+i).ToString("yyyy-MM-dd 23:59:59"));

                    mtBegin = sh.FirstDayOfMonth(tmpTime);
                    jtBegin = DateTime.Parse(sh.GetInceDay(tmpTime));
                    ytBegin = DateTime.Parse(tmpTime.ToString("yyyy-01-01"));

                    tmpDay = sh.DateDiffDays(DateTime.Parse(mTimeEnd), tmpTime);

                    if (tmpDay >= 0)
                        isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                    tmpDay = sh.DateDiffDays(DateTime.Parse(jTimeEnd), tmpTime);

                    if (tmpDay >= 0)
                        isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, jtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                    tmpDay = sh.DateDiffDays(DateTime.Parse(yTimeEnd), tmpTime);

                    if (tmpDay >= 0)
                        isY = this.SaveDate(yPoint, pId, zbType, jz, bname, ytBegin.ToString("yyyy-01-01 0:00:00"), tmpTime.ToString(), 0);

                    if (isM == false || isJ == false || isY == false)
                        return false;
                }

                //当日
                tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(mTimeEnd));

                if (tmpDay == 1 && dtNow.Day != 1)
                    isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(jTimeEnd));

                if (tmpDay == 1 && dtNow.Day != 1)
                    isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(yTimeEnd));

                if (tmpDay == 1 && dtNow.Day != 1)
                    isY = this.SaveDate(yPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-01-01 0:00:00"), dtNow.ToString(), 1);

                if (isM == true && isJ == true && isY == true)
                    flag = true;
            }
            return flag;
        }

        //小时数据保存
        public bool RetIsTrueToSaveHoursNew(string id, string jz, string time, string[] val, string[] bj)
        {
            string hPoint;
            string dPoint;
            string mPoint;
            string yPoint;
            string jPoint;
            string zbType;
            string bname;
            string pId;
            string iJidu = "";
            string nJidu = "";

            bool isD = false;
            bool isM = false;
            bool isJ = false;
            bool isY = false;
            bool isH = false;
            bool flag = false;

            this.init();

            if (jz == "1")
            {
                bname = "实时统计数据表1";
                pName = pGl1;
            }
            else
            {
                bname = "实时统计数据表2";
                pName = pGl2;
            }

            string sql = "select * from T_sheet_sheetPara where ID_key= " + id;

            DataRow drSheet;

            if (rlDBType == "SQL")
                drSheet = DBsql.RunDataRow(sql, out errMsg);
            else
                drSheet = DBdb2.RunDataRow(sql, out errMsg);

            if (drSheet != null)
            {
                hPoint = drSheet["小时点"].ToString();
                dPoint = drSheet["日点"].ToString(); ;
                mPoint = drSheet["月点"].ToString(); ;
                yPoint = drSheet["年点"].ToString(); ;
                jPoint = drSheet["季点"].ToString(); ;
                zbType = drSheet["参数类型"].ToString();

                DateTime input = DateTime.Parse(time);
                DateTime dtNow = DateTime.Now;

                iJidu = sh.GetJidu(input);
                nJidu = sh.GetJidu(dtNow);

                DataRow drS;

                if (rlDBType == "SQL")
                    drS = DBsql.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                else
                    drS = DBdb2.RunDataRow("select * from 实时统计测点表 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表2 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表3 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表4 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                if (drS == null)
                {
                    if (rlDBType == "SQL")
                        drS = DBsql.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                    else
                        drS = DBdb2.RunDataRow("select * from 实时统计测点表5 where 小时测点='" + drSheet["小时点"].ToString() + "'", out errMsg);
                }

                pId = drS["统计ID"].ToString();

                if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                    isH = this.SaveDataHourIS(hPoint, pId, jz, bname, zbType, val, bj, time);
                else
                    isH = this.SaveDataHour(hPoint, pId, jz, bname, zbType, val, bj, time);

                //修改日数据
                if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                    isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                else
                    isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");

                bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");

                bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");

                bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");

                bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                //月末
                if (sh.DateDiffDays(dtNow, input) > dtNow.Day)
                    mTimeEnd = sh.LastDayOfMonth(input).ToString();
                else
                    mTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                //季末
                if (iJidu == nJidu && input.Year == dtNow.Year)
                    jTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");
                else
                    jTimeEnd = sh.GetEndDay(input);

                //年末
                if (input.Year != dtNow.Year)
                    yTimeEnd = input.ToString("yyyy-12-31");
                else
                    yTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                mtBegin = sh.FirstDayOfMonth(input);
                jtBegin = DateTime.Parse(sh.GetInceDay(input));
                ytBegin = DateTime.Parse(input.ToString("yyyy-01-01"));

                for (int i = 0; i <= sh.DateDiffDays(DateTime.Parse(yTimeEnd), input); i++)
                {
                    tmpTime = DateTime.Parse(input.AddDays(+i).ToString("yyyy-MM-dd 23:59:59"));

                    mtBegin = sh.FirstDayOfMonth(tmpTime);
                    jtBegin = DateTime.Parse(sh.GetInceDay(tmpTime));
                    ytBegin = DateTime.Parse(tmpTime.ToString("yyyy-01-01"));

                    tmpDay = sh.DateDiffDays(DateTime.Parse(mTimeEnd), tmpTime);

                    if (tmpDay >= 0)
                        isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                    tmpDay = sh.DateDiffDays(DateTime.Parse(jTimeEnd), tmpTime);

                    if (tmpDay >= 0)
                        isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, jtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                    tmpDay = sh.DateDiffDays(DateTime.Parse(yTimeEnd), tmpTime);

                    if (tmpDay >= 0)
                        isY = this.SaveDate(yPoint, pId, zbType, jz, bname, ytBegin.ToString("yyyy-01-01 0:00:00"), tmpTime.ToString(), 0);

                    if (isM == false || isJ == false || isY == false)
                        return false;
                }

                //当日
                tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(mTimeEnd));

                if (tmpDay == 1 && dtNow.Day != 1)
                    isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(jTimeEnd));

                if (tmpDay == 1 && dtNow.Day != 1)
                    isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(yTimeEnd));

                if (tmpDay == 1 && dtNow.Day != 1)
                    isY = this.SaveDate(yPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-01-01 0:00:00"), dtNow.ToString(), 1);

                if (isM == true && isJ == true && isY == true)
                    flag = true;
            }
            return flag;
        }

        //班值数据保存
        public bool RetIsTrueToSaveBzNew(string id, string jz, string time, string tjID, string[] val, string[] bz)
        {
            string hPoint;
            string dPoint;
            string mPoint;
            string yPoint;
            string jPoint;
            string zbType;
            string bname;
            string pId;
            string iJidu = "";
            string nJidu = "";

            bool isM = false;
            bool isJ = false;
            bool isY = false;
            bool Kt = false;
            bool flag = false;
            bool isD = false;

            if (jz == "1")
                bname = "实时统计数据表1";
            else
                bname = "实时统计数据表2";

            pId = tjID;

            this.init();

            string sql = "select * from T_sheet_sheetPara where ID_key= " + id;

            DataRow drSheet;

            if (rlDBType == "SQL")
                drSheet = DBsql.RunDataRow(sql, out errMsg);
            else
                drSheet = DBdb2.RunDataRow(sql, out errMsg);

            if (drSheet != null)
            {
                hPoint = drSheet["小时点"].ToString();
                dPoint = drSheet["日点"].ToString(); ;
                mPoint = drSheet["月点"].ToString(); ;
                yPoint = drSheet["年点"].ToString(); ;
                jPoint = drSheet["季点"].ToString(); ;
                zbType = drSheet["参数类型"].ToString();

                DateTime input = DateTime.Parse(time);
                DateTime dtNow = DateTime.Now;

                iJidu = sh.GetJidu(input);
                nJidu = sh.GetJidu(dtNow);

                bool isH = this.SaveDataHour(hPoint, bname, pId, time, zbType, jz, val, bz, out  Kt);

                if (Kt == true)
                {
                    string time1 = DateTime.Parse(time).AddDays(-1).ToString();

                    #region 班组跨天
                    if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                    {
                        isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                        isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time1, "0");
                    }
                    else
                    {
                        isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");
                        isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time1, "1");
                    }

                    bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                    bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                    bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                    bool valDay1 = this.SaveValue(pId, jz, zbType, bname, time1, "值日");
                    bool valMon1 = this.SaveValue(pId, jz, zbType, bname, time1, "值月");
                    bool valJidu1 = this.SaveValue(pId, jz, zbType, bname, time1, "值季");
                    bool valYear1 = this.SaveValue(pId, jz, zbType, bname, time1, "值年");

                    //月末
                    if (sh.DateDiffDays(dtNow, DateTime.Parse(time1)) > dtNow.Day)
                        mTimeEnd = sh.LastDayOfMonth(DateTime.Parse(time1)).ToString();
                    else
                        mTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                    //季末
                    if (iJidu == nJidu && DateTime.Parse(time1).Year == dtNow.Year)
                        jTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");
                    else
                        jTimeEnd = sh.GetEndDay(DateTime.Parse(time1));

                    //年末
                    if (DateTime.Parse(time1).Year != dtNow.Year)
                        yTimeEnd = DateTime.Parse(time1).ToString("yyyy-12-31");
                    else
                        yTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                    mtBegin = sh.FirstDayOfMonth(input);
                    jtBegin = DateTime.Parse(sh.GetInceDay(input));
                    ytBegin = DateTime.Parse(input.ToString("yyyy-01-01"));

                    for (int i = 0; i <= sh.DateDiffDays(DateTime.Parse(yTimeEnd), DateTime.Parse(time1)); i++)
                    {
                        tmpTime = DateTime.Parse(DateTime.Parse(time1).AddDays(+i).ToString("yyyy-MM-dd 23:59:59"));

                        mtBegin = sh.FirstDayOfMonth(tmpTime);
                        jtBegin = DateTime.Parse(sh.GetInceDay(tmpTime));
                        ytBegin = DateTime.Parse(tmpTime.ToString("yyyy-01-01"));

                        tmpDay = sh.DateDiffDays(DateTime.Parse(mTimeEnd), tmpTime);

                        if (tmpDay >= 0)
                            isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                        tmpDay = sh.DateDiffDays(DateTime.Parse(jTimeEnd), tmpTime);

                        if (tmpDay >= 0)
                            isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, jtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                        tmpDay = sh.DateDiffDays(DateTime.Parse(yTimeEnd), tmpTime);

                        if (tmpDay >= 0)
                            isY = this.SaveDate(yPoint, pId, zbType, jz, bname, ytBegin.ToString("yyyy-01-01 0:00:00"), tmpTime.ToString(), 0);

                        if (isM == false || isJ == false || isY == false)
                            return false;
                    }

                    //当日
                    tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(mTimeEnd));

                    if (tmpDay == 1 && dtNow.Day != 1)
                        isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                    tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(jTimeEnd));

                    if (tmpDay == 1 && dtNow.Day != 1)
                        isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                    tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(yTimeEnd));

                    if (tmpDay == 1 && dtNow.Day != 1)
                        isY = this.SaveDate(yPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-01-01 0:00:00"), dtNow.ToString(), 1);

                    if (isM == true && isJ == true && isY == true)
                        flag = true;

                    #endregion
                }
                else
                {
                    #region 班组不跨天
                    if (input.Day == dtNow.Day && input.Month == dtNow.Month && input.Year == dtNow.Year)
                        isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "0");
                    else
                        isD = this.SaveDateDayByFH(dPoint, pId, zbType, jz, bname, time, "1");

                    bool valDay = this.SaveValue(pId, jz, zbType, bname, time, "值日");
                    bool valMon = this.SaveValue(pId, jz, zbType, bname, time, "值月");
                    bool valJidu = this.SaveValue(pId, jz, zbType, bname, time, "值季");
                    bool valYear = this.SaveValue(pId, jz, zbType, bname, time, "值年");

                    //月末
                    if (sh.DateDiffDays(dtNow, input) > dtNow.Day)
                        mTimeEnd = sh.LastDayOfMonth(input).ToString();
                    else
                        mTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                    //季末
                    if (iJidu == nJidu && input.Year == dtNow.Year)
                        jTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");
                    else
                        jTimeEnd = sh.GetEndDay(input);

                    //年末
                    if (input.Year != dtNow.Year)
                        yTimeEnd = input.ToString("yyyy-12-31");
                    else
                        yTimeEnd = dtNow.AddDays(-1).ToString("yyyy-MM-dd");

                    mtBegin = sh.FirstDayOfMonth(input);
                    jtBegin = DateTime.Parse(sh.GetInceDay(input));
                    ytBegin = DateTime.Parse(input.ToString("yyyy-01-01"));

                    for (int i = 0; i <= sh.DateDiffDays(DateTime.Parse(yTimeEnd), input); i++)
                    {
                        tmpTime = DateTime.Parse(input.AddDays(+i).ToString("yyyy-MM-dd 23:59:59"));

                        mtBegin = sh.FirstDayOfMonth(tmpTime);
                        jtBegin = DateTime.Parse(sh.GetInceDay(tmpTime));
                        ytBegin = DateTime.Parse(tmpTime.ToString("yyyy-01-01"));

                        tmpDay = sh.DateDiffDays(DateTime.Parse(mTimeEnd), tmpTime);

                        if (tmpDay >= 0)
                            isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                        tmpDay = sh.DateDiffDays(DateTime.Parse(jTimeEnd), tmpTime);

                        if (tmpDay >= 0)
                            isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, jtBegin.ToString("yyyy-MM-01 0:00:00"), tmpTime.ToString(), 0);

                        tmpDay = sh.DateDiffDays(DateTime.Parse(yTimeEnd), tmpTime);

                        if (tmpDay >= 0)
                            isY = this.SaveDate(yPoint, pId, zbType, jz, bname, ytBegin.ToString("yyyy-01-01 0:00:00"), tmpTime.ToString(), 0);

                        if (isM == false || isJ == false || isY == false)
                            return false;
                    }

                    //当日
                    tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(mTimeEnd));

                    if (tmpDay == 1 && dtNow.Day != 1)
                        isM = this.SaveDate(mPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                    tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(jTimeEnd));

                    if (tmpDay == 1 && dtNow.Day != 1)
                        isJ = this.SaveDate(jPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-MM-01 0:00:00"), dtNow.ToString(), 1);

                    tmpDay = sh.DateDiffDays(dtNow, DateTime.Parse(yTimeEnd));

                    if (tmpDay == 1 && dtNow.Day != 1)
                        isY = this.SaveDate(yPoint, pId, zbType, jz, bname, mtBegin.ToString("yyyy-01-01 0:00:00"), dtNow.ToString(), 1);

                    if (isM == true && isJ == true && isY == true)
                        flag = true;

                    #endregion
                }
            }
            return flag;
        }

        public bool SaveDate(string point, string pid, string zbType, string jz, string bname, string qsrq, string jsrq, int isCur)
        {
            int k = -1;

            object obj;
            string sql;
            string sDate;
            object value;

            bool flag = false;

            sDate = jsrq;

            this.init();

            if (zbType == "平均")
            {
                //SQL
                //sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
                //DB2
                sql = "select avg(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组=" + jz + "";
            }
            else
            {
                //SQL
                //sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组='" + jz + "'";
                //DB2
                sql = "select sum(统计值) from " + bname + " where (统计ID = '" + pid + "') and 时间 between '" + qsrq + "' and  '" + jsrq + "' and 标记=1 and 机组=" + jz + "";
            }
            try
            {
                if (rlDBType == "SQL")
                    obj = DBsql.RunSingle(sql, out errMsg);
                else
                    obj = DBdb2.RunSingle(sql, out errMsg);

                if (obj.ToString() == "" || obj == null)
                    value = "0";
                else
                    value = obj;
            }
            catch (Exception ce)
            { value = "0"; }

            if (value.ToString() != "")
            {
                if (rtDBType == "EDNA")
                {
                    if (isCur == 0)
                        k = ek.SetHisValue(ref point, ref sDate, ref value);
                    else
                        k = ek.SetCurValue(ref point, ref value);
                }
                else
                {
                    if (isCur == 0)
                        k = pk.SetHisValue(point, sDate, ref value);// ek.SetHisValue(ref point, ref sDate, ref value);
                    else
                        k = pk.SetCurValue(point, ref value);// //ek.SetCurValue(ref point, ref value);
                }

                if (k == 0)
                    flag = true;
            }
            return flag;
        }

        #endregion

        #region  电量数据维护

        /// <summary>
        /// 电量总体指标读取
        /// </summary>
        /// <param name="dlType">类别ID</param>
        /// <param name="xlID">线路ID</param>
        /// <returns></returns>
        public ArrayList RetArrsDLDescInfo(string dlType, string xlID)
        {
            object objXl = null;
            object objLb = null;
            DataTable dt = null;

            string[] id = new string[500];
            string[] sbDesc = new string[500];
            string[] sbID = new string[500];
            string[] xlID1 = new string[500];
            string[] lbID = new string[500];

            ArrayList list = new ArrayList();

            this.init();

            try
            {
                sql = "SELECT * FROM 电量设备表 where 类别ID='" + dlType + "' and 线路ID='" + xlID + "' order by ID_key asc";

                if (rlDBType == "SQL")
                    dt = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt = DBdb2.RunDataTable(sql, out errMsg);

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    id[i] = dt.Rows[i]["ID_KEY"].ToString();
                    sbDesc[i] = dt.Rows[i]["设备名称"].ToString();
                    sbID[i] = dt.Rows[i]["设备ID"].ToString();

                    sql = "select 线路名称 from 电量线路表 where 线路ID ='" + xlID + "'";

                    if (rlDBType == "SQL")
                        objXl = DBsql.RunSingle(sql, out errMsg);
                    else
                        objXl = DBdb2.RunSingle(sql, out errMsg);

                    if (objXl != null && objXl.ToString() != "")
                        xlID1[i] = objXl.ToString();
                    else
                        xlID1[i] = "&nbsp;";

                    sql = "select 类别名称 from 电量类别表 where 类别ID ='" + dlType + "'";

                    if (rlDBType == "SQL")
                        objLb = DBsql.RunSingle(sql, out errMsg);
                    else
                        objLb = DBdb2.RunSingle(sql, out errMsg);

                    if (objLb != null && objLb.ToString() != "")
                        lbID[i] = objLb.ToString();
                    else
                        lbID[i] = "&nbsp;";
                }
            }
            catch { }

            list.Add(id);
            list.Add(sbDesc);
            list.Add(sbID);
            list.Add(xlID1);
            list.Add(lbID);

            return list;
        }

        /// <summary>
        /// 电量数据读取
        /// </summary>
        /// <param name="sbID"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <returns></returns>
        public ArrayList RetListDLvalue(string sbID, string qsrq, string jsrq)
        {
            string time = "";
            DataTable dtHour = null;

            ArrayList list = new ArrayList();

            string[] value = new string[24];
            string[] date = new string[24];

            this.init();

            sql = "SELECT * FROM 设备表码数据表 where 设备ID='" + sbID + "' and 时间 between '" + qsrq + "' and  '" + jsrq + "' order by 时间 asc";

            if (rlDBType == "SQL")
                dtHour = DBsql.RunDataTable(sql, out errMsg);
            else
                dtHour = DBdb2.RunDataTable(sql, out errMsg);

            if (dtHour.Rows.Count > 0)
            {
                for (int i = 0; i < dtHour.Rows.Count; i++)
                {
                    time = dtHour.Rows[i]["时间"].ToString();

                    date[i] = time;
                    value[i] = dtHour.Rows[i]["表码值"].ToString();
                }
            }
            else
            {
                for (int i = 0; i < 24; i++)
                {
                    value[i] = "";
                    date[i] = DateTime.Parse(qsrq).ToString("yyyy-MM-dd '" + i + "':mm:ss");
                }
            }

            list.Add(value);
            list.Add(date);

            return list;
        }

        /// <summary>
        /// 电量数据保存
        /// </summary>
        /// <param name="sbID"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public bool RetIsTruebyDL(string sbID, string time, string[] val)
        {
            bool isDel = false;
            string qsrq, jsrq;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            this.init();

            sql = "delete from 设备表码数据表 where 设备ID ='" + sbID + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' ";

            if (rlDBType == "SQL")
                isDel = DBsql.RunNonQuery(sql, out errMsg);
            else
                isDel = DBdb2.RunNonQuery(sql, out errMsg);

            if (isDel == true)
            {
                if (val != null)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        if (val[i] != null && val[i] != "")
                        {
                            //SQL
                            //sql = "insert into 设备表码数据表 (设备ID,表码值,时间) values ('" + sbID + "','" + val[i] + "','" + DateTime.Parse(time).AddHours(i).ToString("yyyy-MM-dd H:mm:ss") + "')";
                            //DB2
                            sql = "insert into 设备表码数据表 (设备ID,表码值,时间) values ('" + sbID + "'," + val[i] + ",'" + DateTime.Parse(time).AddHours(i).ToString("yyyy-MM-dd H:mm:ss") + "')";

                            bool isNon = false;

                            if (rlDBType == "SQL")
                                isNon = DBsql.RunNonQuery(sql, out errMsg);
                            else
                                isNon = DBdb2.RunNonQuery(sql, out errMsg);

                            if (isNon == false)
                                return false;
                            else
                                flag = true;
                        }
                    }
                }
            }
            return flag;
        }

        #endregion

        #region  设备换表起码数据表

        /// <summary>
        /// 设备换表起码数据表 读取
        /// </summary>
        /// <param name="sbID"></param>
        /// <param name="qsrq"></param>
        /// <param name="jsrq"></param>
        /// <returns></returns>
        public ArrayList RetListDLvalueSB(string sbID, string qsrq, string jsrq)
        {
            string time = "";
            DataTable dtHour = null;

            ArrayList list = new ArrayList();

            string[] value = new string[24];
            string[] date = new string[24];

            this.init();

            sql = "SELECT * FROM 设备换表起码数据表 where 设备ID='" + sbID + "' and 时间 between '" + qsrq + "' and  '" + jsrq + "' order by 时间 asc";

            if (rlDBType == "SQL")
                dtHour = DBsql.RunDataTable(sql, out errMsg);
            else
                dtHour = DBdb2.RunDataTable(sql, out errMsg);

            if (dtHour.Rows.Count > 0)
            {
                for (int i = 0; i < dtHour.Rows.Count; i++)
                {
                    time = dtHour.Rows[i]["时间"].ToString();

                    date[i] = time;
                    value[i] = dtHour.Rows[i]["表码值"].ToString();
                }
            }
            else
            {
                for (int i = 0; i < 24; i++)
                {
                    value[i] = "";
                    date[i] = DateTime.Parse(qsrq).ToString("yyyy-MM-dd '" + i + "':mm:ss");
                }
            }

            list.Add(value);
            list.Add(date);

            return list;
        }

        /// <summary>
        /// 设备换表起码数据表 保存
        /// </summary>
        /// <param name="sbID"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public bool RetIsTruebyDLSB(string sbID, string time, string[] val)
        {
            string qsrq, jsrq;

            bool flag = false;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            this.init();

            sql = "delete from 设备换表起码数据表 where 设备ID ='" + sbID + "' and 时间 between '" + qsrq + "' and '" + jsrq + "' ";

            bool isDel = false;

            if (rlDBType == "SQL")
                isDel = DBsql.RunNonQuery(sql, out errMsg);
            else
                isDel = DBdb2.RunNonQuery(sql, out errMsg);

            if (isDel == true)
            {
                if (val != null)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        if (val[i] != null && val[i] != "")
                        {
                            sql = "insert into 设备换表起码数据表 (设备ID,表码值,时间) values ('" + sbID + "','" + val[i] + "','" + DateTime.Parse(time).AddHours(i).ToString("yyyy-MM-dd H:mm:ss") + "')";

                            bool isNon = false;

                            if (rlDBType == "SQL")
                                isNon = DBsql.RunNonQuery(sql, out errMsg);
                            else
                                isNon = DBdb2.RunNonQuery(sql, out errMsg);

                            if (isNon == false)
                                return false;
                            else
                                flag = true;
                        }
                    }
                }
            }

            return flag;
        }

        #endregion

        #region T_sheet_sheetPara 维护

        //读取Sheet
        public DataTable retTableByUnitAndRep(int unit, string repName)
        {
            DataTable dt = null;

            this.init();

            sql = " select * from t_sheet_sheetPara where 报表名称='" + repName + "' and 机组=" + unit + " order by ID_KEY asc";

            if (rlDBType == "SQL")
                dt = DBsql.RunDataTable(sql, out errMsg);
            else
                dt = DBdb2.RunDataTable(sql, out errMsg);

            return dt;
        }

        //读取SheetRow
        public DataRow retTableRowByID(string id)
        {
            DataRow dr = null;

            this.init();

            string sql = "select * from T_sheet_sheetPara where ID_KEY=" + id;

            if (rlDBType == "SQL")
                dr = DBsql.RunDataRow(sql, out errMsg);
            else
                dr = DBdb2.RunDataRow(sql, out errMsg);

            return dr;
        }

        public bool retIsTrueBySQL(string sql)
        {
            bool flag = false;

            this.init();

            if (rlDBType == "SQL")
                flag = DBsql.RunNonQuery(sql, out errMsg);
            else
                flag = DBdb2.RunNonQuery(sql, out errMsg);

            return flag;
        }

        #endregion

        #region 电量测点表维护

        /// <summary>
        /// 电量测电表数据
        /// </summary>
        /// <returns></returns>
        public DataTable RetDLPointTable()
        {
            DataTable dt = null;
            this.init();

            string sql = "select * from 电量测点表 order by ID_KEY asc";

            if (rlDBType == "SQL")
                dt = DBsql.RunDataTable(sql, out errMsg);
            else
                dt = DBdb2.RunDataTable(sql, out errMsg);

            return dt;
        }

        /// <summary>
        /// 执行SQL
        /// </summary>
        /// <param name="sql"></param>
        public bool RunNonQuery(string sql)
        {
            this.init();

            bool flag = false;

            if (rlDBType == "SQL")
                flag = DBsql.RunNonQuery(sql, out errMsg);
            else
                flag = DBdb2.RunNonQuery(sql, out errMsg);

            return flag;
        }

        #endregion

        #region  实时计算测点表

        /// <summary>
        /// 实时计算测点表
        /// </summary>
        /// <returns></returns>
        public DataTable RetRTPointTable()
        {
            DataTable dt;
            string sql = "select * from 实时计算测点表 order by ID_KEY asc";

            this.init();

            if (rlDBType == "SQL")
                dt = DBsql.RunDataTable(sql, out errMsg);
            else
                dt = DBdb2.RunDataTable(sql, out errMsg);

            return dt;
        }

        public DataRow RetRTPointTable(string id)
        {
            DataRow dr;
            string sql = "select * from 实时计算测点表 where ID_KEY=" + id;

            this.init();

            if (rlDBType == "SQL")
                dr = DBsql.RunDataRow(sql, out errMsg);
            else
                dr = DBdb2.RunDataRow(sql, out errMsg);
            return dr;
        }


        #endregion

        #region  实时统计测点表

        /// <summary>
        /// 实时统计测点表
        /// </summary>
        /// <returns></returns>
        public DataTable RetRTTJPointTable()
        {
            DataTable dt;
            string sql = "select * from 实时统计测点表 order by ID_KEY asc";

            this.init();

            if (rlDBType == "SQL")
                dt = DBsql.RunDataTable(sql, out errMsg);
            else
                dt = DBdb2.RunDataTable(sql, out errMsg);
            if (dt == null || dt.Rows.Count < 0)
            {
                sql = "select * from 实时统计测点表2 order by ID_KEY asc";
                if (rlDBType == "SQL")
                    dt = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt = DBdb2.RunDataTable(sql, out errMsg);
            }

            if (dt == null || dt.Rows.Count < 0)
            {
                sql = "select * from 实时统计测点表3 order by ID_KEY asc";
                if (rlDBType == "SQL")
                    dt = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt = DBdb2.RunDataTable(sql, out errMsg);
            }

            if (dt == null || dt.Rows.Count < 0)
            {
                sql = "select * from 实时统计测点表4 order by ID_KEY asc";
                if (rlDBType == "SQL")
                    dt = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt = DBdb2.RunDataTable(sql, out errMsg);
            }

            if (dt == null || dt.Rows.Count < 0)
            {
                sql = "select * from 实时统计测点表5 order by ID_KEY asc";
                if (rlDBType == "SQL")
                    dt = DBsql.RunDataTable(sql, out errMsg);
                else
                    dt = DBdb2.RunDataTable(sql, out errMsg);
            }
            return dt;
        }

        public DataRow RetRTTJPointTable(string id)
        {
            DataRow dr;

            string sql = "select * from 实时统计测点表 where ID_KEY=" + id;

            this.init();

            if (rlDBType == "SQL")
                dr = DBsql.RunDataRow(sql, out errMsg);
            else
                dr = DBdb2.RunDataRow(sql, out errMsg);
            if (dr == null)
            {
                sql = "select * from 实时统计测点表2 where ID_KEY=" + id;
                if (rlDBType == "SQL")
                    dr = DBsql.RunDataRow(sql, out errMsg);
                else
                    dr = DBdb2.RunDataRow(sql, out errMsg);
            }

            if (dr == null)
            {
                sql = "select * from 实时统计测点表3 where ID_KEY=" + id;
                if (rlDBType == "SQL")
                    dr = DBsql.RunDataRow(sql, out errMsg);
                else
                    dr = DBdb2.RunDataRow(sql, out errMsg);
            }

            if (dr == null)
            {
                sql = "select * from 实时统计测点表4 where ID_KEY=" + id;
                if (rlDBType == "SQL")
                    dr = DBsql.RunDataRow(sql, out errMsg);
                else
                    dr = DBdb2.RunDataRow(sql, out errMsg);
            }

            if (dr == null)
            {
                sql = "select * from 实时统计测点表5 where ID_KEY=" + id;
                if (rlDBType == "SQL")
                    dr = DBsql.RunDataRow(sql, out errMsg);
                else
                    dr = DBdb2.RunDataRow(sql, out errMsg);
            }
            return dr;
        }


        #endregion

        private string init()
        {
            rlDBType = IniHelper.ReadIniData("RelationDBbase", "DBType", null);
            rtDBType = IniHelper.ReadIniData("RTDB", "DBType", null);
            pGl1 = IniHelper.ReadIniData("Report", "FH1", null);
            pGl2 = IniHelper.ReadIniData("Report", "FH2", null);

            return rlDBType;
        }
    }


}
